package com.qianfeng.zhangwei.camera.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.qianfeng.zhangwei.camera.R;
import com.qianfeng.zhangwei.camera.bean.UploadImage;
import com.qianfeng.zhangwei.camera.linstener.OnItemClick;

import java.util.List;

/**
 * @说 明：
 * @项目名称：Sz1504Adv
 * @包 名： com.qianfeng.zhangwei.camera.adapter
 * @类 名： UploadAdapter
 * @创 建人： zhangwei
 * @创建时间：2015-08-07 10:25
 * @版 本：v1.0
 * @修 改人：
 * @修改时间：
 * @修改备注：
 */
public class UploadAdapter extends RecyclerView.Adapter<UploadAdapter.UploadViewHolder> {
    private List<UploadImage> bitmaps;
    private OnItemClick onItemClick;


    public UploadAdapter(List<UploadImage> bitmaps) {
        this.bitmaps = bitmaps;
    }

    @Override
    public UploadViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.adapter_upload_layout, viewGroup, false);
        UploadViewHolder uvh = new UploadViewHolder(itemView);
        return uvh;
    }

    @Override
    public void onBindViewHolder(UploadViewHolder uploadViewHolder, int i) {
        uploadViewHolder.img.setImageBitmap(bitmaps.get(i).getBitmap());
    }

    @Override
    public int getItemCount() {
        return bitmaps.size();
    }

    public class UploadViewHolder extends RecyclerView.ViewHolder {
        @ViewInject(R.id.item_upload_img)
        private ImageView img;
        @ViewInject(R.id.item_upload_checkbox)
        public CheckBox uploadCheckBox;


        public UploadViewHolder(View itemView) {
            super(itemView);
            ViewUtils.inject(this, itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (onItemClick != null) {
                        onItemClick.onItemClick(UploadViewHolder.this.getLayoutPosition(), UploadViewHolder.this);
                    }

                }
            });

        }
    }


    public OnItemClick getOnItemClick() {
        return onItemClick;
    }

    public void setOnItemClick(OnItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }
}
